<?php
//include("../chk.php");
include("../common/conn.php");
include("../common/publicFun.php");
$do=GetForm("do");
$current_folder_id=CheckNum(GetForm("current_folder_id"),-1,-1);
$name=GetForm("name");
if($current_folder_id==-1 || $name=='')die("<script>msg(0,'权限不足或参数错误',0);</script>");
//die("<script>msg('错误','face-sad','$parentId');</script>");
switch($do){
  case 'create'://创建
    //检查欲建的目录名是否已经存在  //同级目录不能同名，不在同一级目录，可以存在同名目录
    $sql='select id from folder where parentId='.$current_folder_id.' and name='.SqlEncode($name).' and accountId='.$_SESSION[$config_user_session_prefix]['id'];
    $query=mysql_query($sql);
    if(mysql_num_rows($query)){
      die("<script>msg(0,'该目录已存在',0);</script>");
    }
    $arr=array('parentId'=>$current_folder_id,'name'=>$name,'accountId'=>$_SESSION[$config_user_session_prefix]['id']);
    $id=_insert('folder',$arr);
    if($id){
      die("<script>msg(1,'添加成功',1);</script>");
    }else{
      die("<script>msg(0,'添加失败',0);</script>");
    }
    break;
  case 'modity';//修改
    //如果是修改，找出自己的父目录
    $query=mysql_query('select parentId from folder where id='.$current_folder_id);
    $arr=mysql_fetch_array($query);
    $sql='select id from folder where id='.$arr[parentId].' and name='.SqlEncode($name).' and accountId='.$_SESSION[$config_user_session_prefix]['id'];
    $query=mysql_query($sql);
    if(mysql_num_rows($query)){
      die("<script>msg(0,'该目录已存在',0);</script>");
    }
    $arr=array('name'=>$name);
    if(_update('folder',$arr,'id='.$current_folder_id))die("<script>msg(1,'修改成功',1);</script>");
    break;
}
?>